package com.zlsy.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouliang
 * @date 2020/7/4 13:14
 */
public class ShutdownThreadPool {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 1000; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(500);
                        System.out.println(Thread.currentThread().getName());
                    } catch (InterruptedException e) {
                        System.out.println(Thread.currentThread().getName() + "被中断了！");
                    }
                }
            });
        }
        executorService.shutdown();

//        boolean shutdown = executorService.isShutdown();
//        if (!shutdown) {
//            //测试提交新的任务
//            executorService.execute(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(1);
//                }
//            });
//        }
//
//        //线程池是否已经完全停止了
//        boolean terminated = executorService.isTerminated();
//        System.out.println(terminated);
//
//
//        try {
//            //检测自己定义的一段时间结束后线程是否完全的运行结束了。
//            boolean isTerminated = executorService.awaitTermination(30, TimeUnit.SECONDS);
//            System.out.println(isTerminated);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//        List<Runnable> runnables = executorService.shutdownNow();


    }
}
